<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $this->redirect('/usJnIgNOHW.php');
//        return $this->view->fetch();
    }
    
    
    public function dealData(){
       $dir = APP_PATH  . DS .'index' . DS. 'data' . DS ;
       $file_list = scandir($dir);
       $key_arr = ['field','beizhu','type'];
       
        foreach ($file_list as $file){
            if($file == '.' || $file == '..') {
                continue;
            }else{
                if($file == 'Amendian'){
                    $key_arr = ['field','type','beizhu'];
                }
                $exist_key = db('a_field')->column('field');
                $data = [];
                $content = file_get_contents($dir.$file);
                $list = explode("\n", $content);
                foreach ($list as $value){
                    $field_list = explode('	', $value);
                    $middle_data = [];
                    foreach ($key_arr as $k=>$v){
                        $middle_data[$v] = $field_list[$k];
                    }
                    if(!in_array($middle_data['field'], $exist_key)){
                        $data[] = $middle_data;
                    }
                    
                }    
                if(!empty($data)){
                    db('a_field')->insertAll($data);
                }
                
            }
            
       }
       
    }

}
